package com.heima.admin.controller.v1;

import com.heima.admin.service.IAdSensitiveService;
import com.heima.model.admin.dtos.AdSensitiveDTO;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "敏感词数据接口")
@RestController
@RequestMapping("api/v1/sensitive")
public class AdSensitiveController {

    @Autowired
    private IAdSensitiveService adSensitiveService;

    @ApiOperation(value = "查询敏感词", notes = "根据名称分页模糊查询敏感词列表")
    @PostMapping("list")
    public ResponseResult list(@RequestBody AdSensitiveDTO adSensitiveDTO){
        return adSensitiveService.list(adSensitiveDTO);
    }

    @ApiOperation(value = "新增敏感词", notes = "新增敏感词")
    @PostMapping("save")
    public ResponseResult insert(@RequestBody AdSensitive adSensitive){
        return adSensitiveService.insert(adSensitive);
    }

    @ApiOperation(value = "修改敏感词", notes = "修改敏感词")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdSensitive adSensitive){
        return adSensitiveService.update(adSensitive);
    }

    @ApiOperation(value = "删除敏感词", notes = "根据 ID 删除敏感词信息")
    @GetMapping("del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return adSensitiveService.delete(id);
    }

    @ApiOperation(value = "查询敏感词集合", notes = "查询敏感词集合")
    @PostMapping("sensitives")
    public ResponseResult findAllSensitives(){
        List<String> sensitives = adSensitiveService.list().stream().map(adSensitive -> adSensitive.getSensitives()).collect(Collectors.toList());
        return ResponseResult.okResult(sensitives);
    }
}
